﻿using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System.Reflection;

namespace StarsAdmin.Core.Extensions.Json
{
    public class CustomContractResolver : DefaultContractResolver
    {
        protected override string ResolvePropertyName(string propertyName)
        {
            var property = base.ResolvePropertyName(propertyName);

            return char.ToLower(property[0]) + property.Substring(1);
        }

        protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
        {
            var property = base.CreateProperty(member, memberSerialization);
            property.ValueProvider = new CollectionValueProperty(property.ValueProvider);
            return property;
        }
    }
}